<template>
  <div class="app-container">
    <label class="title" style="font-size: 20px;color: rgba(0,0,0,.85);font-weight: 600;line-height: 32px">考试异议记录</label>
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="关键字" prop="main">
        <el-input
          v-model="queryParams.main"
          placeholder="准考证、考生姓名、考试项目"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="recordList">
      <el-table-column label="序号" type="index" align="center">
        <template slot-scope="scope">
          <span>{{scope.$index+(queryParams.pageNo-1)*queryParams.pageSize+1}}</span>
        </template>
      </el-table-column>
      <el-table-column label="准考证" align="center" prop="zkz" />
      <el-table-column label="考生姓名" align="center" prop="ksName" />
      <el-table-column label="考试项目" align="center" prop="examName" />
      <el-table-column label="考点" align="center" prop="pointName" />
      <el-table-column label="原因" align="center" prop="reason" />
      <el-table-column label="类型" align="center" prop="type">
        <template slot-scope="scope">
          <dict-tag-remark :options="dict.type.specialTypes" :value="scope.row.type"/>
        </template>
      </el-table-column>
      <el-table-column label="之前结果" align="center" prop="beforeResult" />
      <el-table-column label="改后结果" align="center" prop="afterResult" />
      <el-table-column label="操作人" align="center" prop="actionPeople" />
      <el-table-column label="操作时间" align="center" prop="actionTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.actionTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['business:record:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['business:record:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNo"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改异议处理记录对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="考生id" prop="ksId">
          <el-input v-model="form.ksId" placeholder="请输入考生id" />
        </el-form-item>
        <el-form-item label="项目id" prop="examId">
          <el-input v-model="form.examId" placeholder="请输入项目id" />
        </el-form-item>
        <el-form-item label="考点id" prop="pointId">
          <el-input v-model="form.pointId" placeholder="请输入考点id" />
        </el-form-item>
        <el-form-item label="异议类型" prop="objectionType">
          <el-select v-model="form.objectionType" placeholder="请选择异议类型">
            <el-option label="请选择字典生成" value="" />
          </el-select>
        </el-form-item>
        <el-form-item label="之前的结果" prop="beforeResult">
          <el-input v-model="form.beforeResult" placeholder="请输入之前的结果" />
        </el-form-item>
        <el-form-item label="改后的结果" prop="afterResult">
          <el-input v-model="form.afterResult" placeholder="请输入改后的结果" />
        </el-form-item>
        <el-form-item label="原因" prop="reason">
          <el-input v-model="form.reason" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="处理人" prop="handler">
          <el-input v-model="form.handler" placeholder="请输入处理人" />
        </el-form-item>
        <el-form-item label="处理日期" prop="handlerDate">
          <el-date-picker clearable size="small"
                          v-model="form.handlerDate"
                          type="date"
                          value-format="yyyy-MM-dd"
                          placeholder="选择处理日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="创建时间" prop="gmtCreated">
          <el-date-picker clearable size="small"
                          v-model="form.gmtCreated"
                          type="date"
                          value-format="yyyy-MM-dd"
                          placeholder="选择创建时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="更新时间" prop="gmtModified">
          <el-date-picker clearable size="small"
                          v-model="form.gmtModified"
                          type="date"
                          value-format="yyyy-MM-dd"
                          placeholder="选择更新时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="删除标记" prop="isDeleted">
          <el-input v-model="form.isDeleted" placeholder="请输入删除标记" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
    import { listRecord } from "@/api/business/examSpecialRecord/examSpecialRecord";

    export default {
        name: "Record",
        dicts: ['specialTypes'],
        data() {
            return {
                // 遮罩层
                loading: true,
                // 导出遮罩层
                exportLoading: false,
                // 选中数组
                ids: [],
                // 非单个禁用
                single: true,
                // 非多个禁用
                multiple: true,
                // 显示搜索条件
                showSearch: true,
                // 总条数
                total: 0,
                // 异议处理记录表格数据
                recordList: [],
                // 弹出层标题
                title: "",
                // 是否显示弹出层
                open: false,
                // 查询参数
                queryParams: {
                    pageNo: 1,
                    pageSize: 10,
                    main: null
                },
                // 表单参数
                form: {},
                // 表单校验
                rules: {
                    ksId: [
                        { required: true, message: "考生id不能为空", trigger: "blur" }
                    ],
                    examId: [
                        { required: true, message: "项目id不能为空", trigger: "blur" }
                    ],
                    pointId: [
                        { required: true, message: "考点id不能为空", trigger: "blur" }
                    ],
                    objectionType: [
                        { required: true, message: "异议类型不能为空", trigger: "change" }
                    ],
                    handler: [
                        { required: true, message: "处理人不能为空", trigger: "blur" }
                    ],
                    handlerDate: [
                        { required: true, message: "处理日期不能为空", trigger: "blur" }
                    ],
                }
            };
        },
        created() {
            this.getList();
        },
        methods: {
            /** 查询异议处理记录列表 */
            getList() {
                this.loading = true;
                listRecord(this.queryParams).then(response => {
                    this.recordList = response.data.records;
                    this.total = response.data.totalCount;
                    this.loading = false;
                });
            },
            // 取消按钮
            cancel() {
                this.open = false;
                this.reset();
            },
            // 表单重置
            reset() {
                this.form = {
                    id: null,
                    ksId: null,
                    examId: null,
                    pointId: null,
                    objectionType: null,
                    beforeResult: null,
                    afterResult: null,
                    reason: null,
                    handler: null,
                    handlerDate: null,
                    gmtCreated: null,
                    gmtModified: null,
                    isDeleted: null
                };
                this.resetForm("form");
            },
            /** 搜索按钮操作 */
            handleQuery() {
                this.queryParams.pageNo = 1;
                this.getList();
            },
            /** 重置按钮操作 */
            resetQuery() {
                this.resetForm("queryForm");
                this.handleQuery();
            },
            /** 新增按钮操作 */
            handleAdd() {
                this.reset();
                this.open = true;
                this.title = "添加异议处理记录";
            },
            /** 修改按钮操作 */
            handleUpdate(row) {
                this.reset();
                const id = row.id || this.ids
                getRecord(id).then(response => {
                    this.form = response.data;
                    this.open = true;
                    this.title = "修改异议处理记录";
                });
            },
            /** 提交按钮 */
            submitForm() {
                this.$refs["form"].validate(valid => {
                    if (valid) {
                        if (this.form.id != null) {
                            updateRecord(this.form).then(response => {
                                this.$modal.msgSuccess("修改成功");
                                this.open = false;
                                this.getList();
                            });
                        } else {
                            addRecord(this.form).then(response => {
                                this.$modal.msgSuccess("新增成功");
                                this.open = false;
                                this.getList();
                            });
                        }
                    }
                });
            },
            /** 删除按钮操作 */
            handleDelete(row) {
                const ids = row.id || this.ids;
                this.$modal.confirm('是否确认删除异议处理记录编号为"' + ids + '"的数据项？').then(function() {
                    return delRecord(ids);
                }).then(() => {
                    this.getList();
                    this.$modal.msgSuccess("删除成功");
                }).catch(() => {});
            },
            /** 导出按钮操作 */
            handleExport() {
                const queryParams = this.queryParams;
                this.$modal.confirm('是否确认导出所有异议处理记录数据项？').then(() => {
                    this.exportLoading = true;
                    return exportRecord(queryParams);
                }).then(response => {
                    this.$download.name(response.msg);
                    this.exportLoading = false;
                }).catch(() => {});
            }
        }
    };
</script>
